<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<div class="project_contents">
	<h1>Work</h1>
	<div class="project_in">
		<h2>${work.workType } #${work.workNo }</h2>
		<div id="work_buttons">
			<input type="button" class="btn" value="목록"
				onclick="project_worklist()" /> <input type="button" class="btn"
				value="수정" onclick="project_work_modify(${work.workNo})" /> <input
				type="button" class="btn" value="삭제"
				onclick="project_work_delete(${work.workNo})" />
		</div>
		<table  id="project_work_content">
			<tr>
				<th colspan="4" class="left border-bottom" id="work-title">${work.workTitle }</th>
			</tr>
			<tr>
				<th>상<span class="nbsp"></span>태</th>
				<td>${work.workState}</td>
				<th>시작 시간</th>
				<td><fmt:formatDate value="${work.workStartTime }" type="both" /></td>
			</tr>
			<tr>
				<th>우선 순위</th>
				<td>${work.workPriority }</td>
				<th>마감 시간</th>
				<td><c:choose>
						<c:when test="${work.workDeadTime==null}">미지정</c:when>
						<c:otherwise>
							<fmt:formatDate value="${work.workDeadTime }" type="both" />
						</c:otherwise>
					</c:choose></td>
			</tr>
			<tr>
				<th>진 척 도</th>
				<td>${work.workProgress}%</td>
				<th>업무관계자</th>
				<td>${work.coWorkers}</td>
			</tr>
			<tr>
				<th>담 당 자</th>
				<td colspan="3">${work.name }</td>
			</tr>
			<tr>
				<th>연결된 파일</th>
				<td class="text-over">
				<div  class="over-text">
				<c:choose>
						<c:when test="${file != null}">
							<a href="${file.filePath }">${file.fileName }</a>
						</c:when>
						<c:otherwise>
							<div id="choose_file">
								<select id="form_file">
									<option>--고르세요--</option>
								</select> 
								<input type="button" value="파일 연결"
									onclick="updateFileInWorkPage(${work.workNo})">
							</div>
							<span id="span_addFile">추가</span>
						</c:otherwise>
					</c:choose>
				</div>
				</td>
				<th>연결된 문서</th>
				<td><c:choose>
						<c:when test="${doc != null }">
							<span id="span_addFile" onclick="document_pick(${doc.docNo})">
							${doc.docTitle}</span>
						</c:when>
						<c:otherwise>
							<div id="choose_document">
								<select id="form_document">
									<option>--고르세요--</option>
								</select> <input type="button" value="문서 연결"
									onclick="updateDocumentInWorkPage(${work.workNo})">
							</div>
							<span id="span_addDoc">추가</span>
						</c:otherwise>
					</c:choose></td>
			</tr>
			<tr>
				<th colspan="4" class="left border-top">설<span class="nbsp"></span>명</th>
			</tr>
			<tr>
				<td colspan="4" class="border-bottom">
					<div id="workExplanation">${work.workExplanation }</div>
				</td>
			</tr>
			<tr>
				<th colspan="3" class="left">상위 일감</th>
				<td><span id="span_addUpperWork">추가</span></td>
			</tr>
			<c:choose>
				<c:when test="${upperWork != null }">
					<tr>
						<td>
						<span>${upperWork.workState}</span>
						<span>${upperWork.workPriority }</span>
						</td>
						<td colspan="3">
						<span onclick="pick_upperWork(${upperWork.workNo})"	id="span_upperWork">
						${upperWork.workType} #${upperWork.workNo } : ${upperWork.workTitle}</span>
						</td>
						
					</tr>
				</c:when>
				<c:otherwise>
					<tr>
						<td colspan="4">
							<div id="choose_upperWork">
								<select id="form_upperWork">
									<option>--고르세요--</option>
								</select> <input type="button" value="상위일감 추가"
									onclick="updateUpperWorkInWorkPage(${work.workNo})">
							</div>
						</td>
					</tr>
				</c:otherwise>
			</c:choose>

			<tr>
				<th colspan="3" class="left">하위 일감</th>
				<td><span onclick="createChildWork(${work.workNo})"
					id="span_addDownerWork">추가</span></td>
			</tr>
			<c:if test="${downerWorkList != null }">
				<c:forEach var="downerWork" items="${downerWorkList }">
					<tr>
						<td><span>${downerWork.workState}</span>
						<span>${downerWork.workPriority}</span>
						<span>${downerWork.id}</span></td>
					
						<td colspan="3"><span onclick="pick_downerWork(${downerWork.workNo})"id="span_downerWork">
							${downerWork.workType} #${downerWork.workNo } : ${downerWork.workTitle}
							</span>
						</td>
						
					</tr>
				</c:forEach>
			</c:if>
		</table>
		
		<script type="text/javascript">
			$(document).ready(function(){
				$('#choose_upperWork').css({'display':'none'});
				$('#choose_document').css({'display':'none'});
				$('#choose_file').css({'display':'none'});
				
				$('#span_addUpperWork').click(function(){
					$('#choose_upperWork').css({'display':'block'});
					$('#span_addUpperWork').css({'display':'none'});
				});
				
				$('#span_addDoc').click(function(){
					$('#span_addDoc').css({'display':'none'});
					$('#choose_document').css({'display':'block'});
				});
				
				$('#span_addFile').click(function(){
					$('#span_addFile').css({'display':'none'});
					$('#choose_file').css({'display':'block'});
				});
				
				$.ajax({
					url : "project/createWork/getWorkData",
					//				type : "POST",
					cache : false,
					contentType : "application/json; charset=UTF-8",
					success : function(data) {
						var obj = eval(data);
						for( var val in obj){
							$('select#form_upperWork').append("<option value="+obj[val].to+">#"+obj[val].to+" "+obj[val].title+"</option>");
						}
					}
				});
				$.ajax({
					url : "project/createWork/getDocData",
					//				type : "POST",
					cache : false,
					contentType : "application/json; charset=UTF-8",
					success : function(data) {
						var obj = eval(data);
						for( var val in obj){
							$('select#form_document').append("<option value="+obj[val].to+">#"+obj[val].to+" "+obj[val].title+"</option>");
						}
					}
				});
				$.ajax({
					url : "project/createWork/getFileData",
					//				type : "POST",
					cache : false,
					contentType : "application/json; charset=UTF-8",
					success : function(data) {
						var obj = eval(data);
						for( var val in obj){
							$('select#form_file').append("<option value="+obj[val].to+">#"+obj[val].to+" "+obj[val].title+"</option>");
						}
					}
				});
				
				
			});
			
		</script>

	</div>
</div>
